package com.learn.resp;

import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @author DJJ_F
 * @version 1.0
 * @date 2025/07/30
 * @description
 */
// 链式调用
@Accessors(chain = true)
@Data
public class Result<T> {
    private String code;
    private String message;
    private T data;
    private Long timestamp;

    public Result() {
        this.timestamp = System.currentTimeMillis();
    }

    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setCode(ReturnCodeEnum.RC200.getCode());
        result.setMessage(ReturnCodeEnum.RC200.getMessage());
        result.setData(data);
        return result;
    }
    public static <T> Result<T> fail(String code, String message) {
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setMessage(message);
        result.setData(null);
        return result;
    }
}
